
$(function () {
    var commonYear = (new Date()).getFullYear();
    var zcyjgList;//获取仲裁机构字典
    $('[page-href]').click(function () {
        var src = $(this).attr('page-href');
        window.parent.changeMainPage(src);
    })
    layui.use(['form', 'laydate'], function () {
        var laydate = layui.laydate;
        //年选择器
        laydate.render({
            elem: '#year',
            type: 'year',
            value: (new Date()).getFullYear(),
            min: -366,
            max: 0,
            done: function (value, date) {
                commonYear = value;
                getzcyjgList()
            },
            // change: function(value, date){ //监听日期被切换
            //     commonYear = value;
            //     setModelMain()
            // }
        });
        $(".tab_item").on("click", function () {
            $(this).addClass("active").siblings().removeClass("active")
            init()
        })
        getzcyjgList()// 获取仲裁机构字典 设置为同步方法
        function getzcyjgList() {
            $$.ajaxRequest(ajaxUrl2 + "/lemis/business/dp/tsInterface",
                {
                    method: "queryTheDictionary",
                    source: 3,
                    dType: 1,
                },
                function (res) {
                    zcyjgList = (res.data || []).map(item => {
                        return {
                            label: item.name,
                            value: item.pid
                        }
                    });
                    init()
                }
            );
        }
        function init() {
            getdatas(0)
        }
        function getdatas(pageIndex, where) {
            var dType = $(".tab_item.active").attr("data-i")
            if(dType==2){
                setVideo({
                    id: "#stBox",
                    showPageNumber: true,
                    totalrow:"",
                    datas:[{
                        url:"/zzshzc/img/zjzc/111.mp4"
                    },{ url:"/zzshzc/img/zjzc/222.mp4"},{ url:"/zzshzc/img/zjzc/333.mp4"}],
                    searchColumn: [
                        { name: "仲裁院", field: "abz345", type: "select", dicData: zcyjgList },
                        { name: "仲裁员", field: "POP1_1", type: "text" },
                        { name: "案号", field: "abb016", type: "text" },
                        { name: "时间起", field: "abb013Start", type: "datePicker", range: false, subtype: "date", format: 'yyyy年MM月dd日' },
                        { name: "时间止", field: "abb013End", type: "datePicker", range: false, subtype: "date", format: 'yyyy年MM月' }
                    ],
                })
            }
           
            // var params = Object.assign(
            //     {
            //         method: "wisdomArbitrationEight",
            //         source: 3,
            //         pageNumber: pageIndex,
            //         pageSize: 10,
            //         dType: dType,
            //         administrativeDivisionCode: 330000,
            //         year: commonYear,
            //     }, where || {}
            // )
            // $$.ajaxRequest(ajaxUrl2 + "/lemis/business/dp/tsInterface", params,
            //     function (res) {
                   
            //     });
        }
        function setVideo(config, mainClass) {
            config.where = config.where || {}
            var id = config.id
            var formHTML = '';
            var data_ = config.datas || []
            if (config.searchColumn && config.searchColumn.length > 0) {
                formHTML = `<div class="search_column"><form class="layui-form" action="" lay-filter="allUnitsForm">`
                $.each(config.searchColumn, function (i, item) {
                    if (item.type == 'select') {
                        var selectHTML = '';
                        $.each(item.dicData, function (i, item) {
                            selectHTML += `<option value="${item.value}">${item.label}</option>`;
                        })
                        formHTML += `<div class="layui-inline">
                                <label class="layui-form-label">${item.name}</label>
                                <div class="layui-input-inline">
                                    <select name="${item.field}" lay-verify="">
                                        <option value="">请选择</option>
                                        ${selectHTML}
                                    </select>  
                                </div>
                            </div>`;
                    } else if (item.type == 'datePicker') {
                        formHTML += `<div class="layui-inline">
                                    <label class="layui-form-label">${item.name}</label>
                                    <div class="layui-input-inline">
                                        <input type="text" class="layui-input" data-type="datePicker" data-index="${i}" id="${item.field}" />
                                    </div>
                                </div>`;
                    } else if (item.type == 'dropdown') {
                        formHTML += `<div class="layui-inline">
                                    <label class="layui-form-label">${item.name}</label>
                                    <div class="layui-input-inline">
                                        <div class="layui-input"  data-type="dropdown" data-index="${i}" id="${item.field}" ><div class="text text_overflow">请选择</div><i class="layui-icon layui-icon-down layui-font-12"></i></div>
                                    </div>
                                </div>`;
                    } else if (item.type == 'tree') {
                        formHTML += `<button class="layui-btn" id="demo1">
                    ${item.name}
                    <i class="layui-icon layui-icon-down layui-font-12"></i>
                  </button>`
                    } else {
                        formHTML += `<div class="layui-inline">
                                <label class="layui-form-label">${item.name}</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="${item.field}" placeholder="请输入" autocomplete="off" class="layui-input" />
                                </div>
                            </div>`;
                    }
                });
                formHTML += '<button lay-submit class="layui-btn layui-btn-normal" lay-filter="allUnitsForm">查询</button>   </form></div>'
            }
            // $(id).before(formHTML)
            var ecm = "main_box"
            layui.use(['jquery', 'laydate', 'layedit', 'form'], function () {
                //dropdown = layui.dropdown
                var form = layui.form, $ = layui.jquery, laydate = layui.laydate;
                form.render();
                form.render('select', 'allUnitsForm');
                $('.' + ecm).parent().find('[data-type="datePicker"]').each(function (i, ele) {
                    var index = $(this).attr('data-index');
                    laydate.render({
                        elem: '#' + config.searchColumn[index].field,
                        type: config.searchColumn[index].subtype,
                        range: config.searchColumn[index].range || false,
                        format: config.searchColumn[index].format,
                        done: function (value, date, endDate) {
                            //aae036StartTime/aae036EndTime
                            // console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
                            // console.log(endDate); //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。
                            var startTime = {
                                year: date.year || '',
                                month: date.month ? moreThanTen(date.month) : '',
                                date: date.date ? moreThanTen(date.date) : ''
                            };
                            var endTime = {
                                year: endDate.year || '',
                                month: date.month ? moreThanTen(endDate.month) : '',
                                date: date.date ? moreThanTen(endDate.date) : ''
                            };
                            config.where[config.searchColumn[index].field + 'StartTime'] = startTime.year + startTime.month + startTime.date;
                            config.where[config.searchColumn[index].field + 'EndTime'] = endTime.year + endTime.month + endTime.date;
                        }
                    });
                })
                $('.' + ecm).parent().find('[data-type="dropdown"]').each(function (i, ele) {
                    var index = $(this).attr('data-index');
                    // dropdown.render({
                    //     elem: '#'+data.searchColumn[index].field,
                    //     data: data.searchColumn[index].dicData,
                    //     click: function(obj){
                    //         $(ele+' .text').text(obj.title)
                    //         data.where[data.searchColumn[index].field] = obj.id;
                    //     },
                    //   });
                    //   return;
                    renderDropdown({
                        elem: '#' + config.searchColumn[index].field,
                        data: config.searchColumn[index].dicData,
                        textclick: function (obj) {
                            $(ele).find(' .text').text(obj.title)
                            config.where[config.searchColumn[index].field] = obj.id;
                        },
                        iconClick: function () {

                        }
                    });

                })
                form.on('submit(allUnitsForm)', function (formData) {
                    console.log(formData.field) //当前容器的全部表单字段，名值对形式：{name: value}
                    $.each(formData.field, function (k, val) {
                        config.where[k] = val;
                    })
                    setData(0);
                    $(id + ' .pagenation .page_num').eq(0).addClass('active').siblings().removeClass('active');
                    return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
                });
            })
            var pageHTML = '<div class="page_last "></div>', pageSize = config.pageSize || 10,
                pages = Math.ceil(data_.length / pageSize), pageIndex = 0, nextIndex = 0;
            data_ = data_.map((item, i) => {
                item.pm = i + 1;
                return item;
            })
            while (pages > 0) {
                pageIndex++;
                pageHTML += '<div class="' + (config.showPageNumber ? 'page_num' : '') + '">' + (config.showPageNumber ? pageIndex : '') + '</div>';
                pages--;
            };
            nextIndex = pageIndex
            pageHTML += `<div class="page_next"></div>`
            // $(id + " .pagenation").html(pageHTML)
            $(id + ' .pagenation .page_num').eq(0).addClass('active');
            $(id + ' .pagenation .page_num').click(function () {
                var index = $(this).index() - 1;
                nextIndex = index
                setData(index);
                $(this).addClass('active').siblings().removeClass('active');
            });
            $(id + ' .pagenation .page_next').click(function () {
                ++nextIndex
                setData(nextIndex);
                $(this).addClass('active').siblings().removeClass('active');
            });
            $(id + ' .pagenation .page_last').click(function () {
                --nextIndex
                setData(nextIndex);
                $(this).addClass('active').siblings().removeClass('active');
            });
            setData(0)
            function setData(pageIndex) {
                var dataHTML = '';
                var i = 0;
                var data = data_.slice(pageIndex * pageSize, (pageIndex + 1) * pageSize);
                if (data.length > 0) {
                  
                    $.each(data, function (i, item) {
                        dataHTML += ` <div class="video_box" data=i="">
                    <div class="video_main">
                    <video id="my_video" height="100%" width="100%"  controls>
                       <source src="${item.url}" >
                       不支持播放该视频
                    </video>
                    </div>
                    <div class="video_text" title=""></div>
                  </div>`
                    })
                        // dataHTML += '<div class="item text_overflow pm_'+(data[i].pm)+'"><div class="pm_box"><span>TOP '+(moreThanTen(data[i].pm||1))+'</span></div>'+(data[i].gz_value||0)+'</div>';
                  
                    $(id + ' .datalist').html(dataHTML);
                }

            }
        }
        function setVideo1(config, mainClass) {
            config.where = config.where || {}
            var id = config.id
            var formHTML = '';
            var data_ = config.datas || []
            if (config.searchColumn && config.searchColumn.length > 0) {
                formHTML = `<div class="search_column"><form class="layui-form" action="" lay-filter="allUnitsForm">`
                $.each(config.searchColumn, function (i, item) {
                    if (item.type == 'select') {
                        var selectHTML = '';
                        $.each(item.dicData, function (i, item) {
                            selectHTML += `<option value="${item.value}">${item.label}</option>`;
                        })
                        formHTML += `<div class="layui-inline">
                                <label class="layui-form-label">${item.name}</label>
                                <div class="layui-input-inline">
                                    <select name="${item.field}" lay-verify="">
                                        <option value="">请选择</option>
                                        ${selectHTML}
                                    </select>  
                                </div>
                            </div>`;
                    } else if (item.type == 'datePicker') {
                        formHTML += `<div class="layui-inline">
                                    <label class="layui-form-label">${item.name}</label>
                                    <div class="layui-input-inline">
                                        <input type="text" class="layui-input" data-type="datePicker" data-index="${i}" id="${item.field}" />
                                    </div>
                                </div>`;
                    } else if (item.type == 'dropdown') {
                        formHTML += `<div class="layui-inline">
                                    <label class="layui-form-label">${item.name}</label>
                                    <div class="layui-input-inline">
                                        <div class="layui-input"  data-type="dropdown" data-index="${i}" id="${item.field}" ><div class="text text_overflow">请选择</div><i class="layui-icon layui-icon-down layui-font-12"></i></div>
                                    </div>
                                </div>`;
                    } else if (item.type == 'tree') {
                        formHTML += `<button class="layui-btn" id="demo1">
                    ${item.name}
                    <i class="layui-icon layui-icon-down layui-font-12"></i>
                  </button>`
                    } else {
                        formHTML += `<div class="layui-inline">
                                <label class="layui-form-label">${item.name}</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="${item.field}" placeholder="请输入" autocomplete="off" class="layui-input" />
                                </div>
                            </div>`;
                    }
                });
                formHTML += '<button lay-submit class="layui-btn layui-btn-normal" lay-filter="allUnitsForm">查询</button>   </form></div>'
            }
            $(id).siblings(".search_column").remove()
            $(id).before(formHTML)
            var ecm = "main_box"
            layui.use(['jquery', 'laydate', 'layedit', 'form'], function () {
                //dropdown = layui.dropdown
                var form = layui.form, $ = layui.jquery, laydate = layui.laydate;
                form.render();
                form.render('select', 'allUnitsForm');
                $('.' + ecm).parent().find('[data-type="datePicker"]').each(function (i, ele) {
                    var index = $(this).attr('data-index');
                    laydate.render({
                        elem: '#' + config.searchColumn[index].field,
                        type: config.searchColumn[index].subtype,
                        range: config.searchColumn[index].range || false,
                        format: config.searchColumn[index].format,
                        done: function (value, date, endDate) {
                            //aae036StartTime/aae036EndTime
                            // console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
                            // console.log(endDate); //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。
                            var startTime = {
                                year: date.year || '',
                                month: date.month ? moreThanTen(date.month) : '',
                                date: date.date ? moreThanTen(date.date) : ''
                            };
                            var endTime = {
                                year: endDate.year || '',
                                month: date.month ? moreThanTen(endDate.month) : '',
                                date: date.date ? moreThanTen(endDate.date) : ''
                            };
                            config.where[config.searchColumn[index].field + 'StartTime'] = startTime.year + startTime.month + startTime.date;
                            config.where[config.searchColumn[index].field + 'EndTime'] = endTime.year + endTime.month + endTime.date;
                            $('#' + config.searchColumn[index].field).attr('disabled', 'disabled');
                        }
                    });
                })
                $('.' + ecm).parent().find('[data-type="dropdown"]').each(function (i, ele) {
                    var index = $(this).attr('data-index');
                    // dropdown.render({
                    //     elem: '#'+data.searchColumn[index].field,
                    //     data: data.searchColumn[index].dicData,
                    //     click: function(obj){
                    //         $(ele+' .text').text(obj.title)
                    //         data.where[data.searchColumn[index].field] = obj.id;
                    //     },
                    //   });
                    //   return;
                    renderDropdown({
                        elem: '#' + config.searchColumn[index].field,
                        data: config.searchColumn[index].dicData,
                        textclick: function (obj) {
                            $(ele).find(' .text').text(obj.title)
                            config.where[config.searchColumn[index].field] = obj.id;
                        },
                        iconClick: function () {

                        }
                    });
                })
                form.on('submit(allUnitsForm)', function (formData) {
                    console.log(formData.field) //当前容器的全部表单字段，名值对形式：{name: value}
                    $.each(formData.field, function (k, val) {
                        config.where[k] = val;
                    })
                    setData(0, config.where);
                    $(id + ' .pagenation .page_num').eq(0).addClass('active').siblings().removeClass('active');
                    return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
                });
            })
            var pageHTML = '<div class="page_last "></div>', pageSize = config.pageSize || 10,
                pages = Math.ceil(config.totalrow / pageSize), pageIndex = 0, nextIndex = 0;
            pagesnum = pages
            // data_ = data_.map((item,i)=>{
            // item.pm = i+1;
            // return item;
            //  })
            while (pages > 0) {
                pageIndex++;
                pageHTML += '<div class="' + (config.showPageNumber ? 'page_num' : '') + '">' + (config.showPageNumber ? pageIndex : '') + '</div>';
                pages--;
            };
            nextIndex = pageIndex
            pageHTML += `<div class="page_next"></div>`
            $(id + " .pagenation").html(pageHTML)
            $(id + ' .pagenation .page_num').eq(0).addClass('active');
            $(id + ' .pagenation .page_num').click(function () {
                var index = $(this).index() - 1;
                nextIndex = index
                setData(index);
                $(this).addClass('active').siblings().removeClass('active');
            });
            $(id + ' .pagenation .page_next').click(function () {
                ++nextIndex
                if (pagesnum > nextIndex) {
                    setData(nextIndex);
                    $(this).addClass('active').siblings().removeClass('active');
                }
            });
            $(id + ' .pagenation .page_last').click(function () {
                if (pagesnum > nextIndex) {
                    --nextIndex
                    setData(nextIndex);
                    $(this).addClass('active').siblings().removeClass('active');
                }

            });
            setData(0)
            function setData(pageIndex, where) {
                var dType = $(".tab_item.active").attr("data-i")
                var params = Object.assign(
                    {
                        method: "wisdomArbitrationEight",
                        source: 3,
                        pageNumber: pageIndex,
                        pageSize: 10,
                        dType: dType,
                        administrativeDivisionCode: 330000,
                        year: commonYear,
                    }, where || {}
                )
                $$.ajaxRequest(ajaxUrl2 + "/lemis/business/dp/tsInterface", params,
                    function (res) {
                        var dataHTML = '';
                        var data = res.data.list || [];
                        if (data.length > 0) {
                            $.each(data, function (i, item) {
                                dataHTML += ` <div class="video_box" data=i="${item.abz301}">
                            <div class="video_main">
                            <video id="my_video" height="100%" width="100%"  controls>
                               <source src="" >
                               不支持播放该视频
                            </video>
                            </div>
                            <div class="video_text" title="${item.abb016}">${item.abb016}</div>
                          </div>`
                            })
                            $(id + ' .datalist').html(dataHTML);
                            $(id + " .video_box").on("click", function () {
                                var id = $(this).attr("data-i")
                                alertZBviDeiDetails(id)
                            })
                        } else {
                            $(id + ' .datalist').html(`<div style=" text-align: center; width: 100%; height: 100%;">暂无数据</div>`);
                            $(id + " .pagenation").html(" ")
                        }
                    });


            }
        }
        //  alertZBviDeiDetails("")
        function alertZBviDeiDetails(abz301) {
            var ecm = $$.alert("axzs");
            $("#" + ecm).html(`     
                        <div class="title">详情</div>
                        <div class="table_con">
                       <div class="text_inifo_box">
                          <div class="model">
                          <div class="model_title">基本信息：</div>
                          <div class="model_content ztxxTable"></div>
                          </div>
                      <div class="model">
                          <div class="model_title">劳动者（申请人）：</div>
                          <div class="news ztxxTable1"></div>
                      </div>
                      <div class="model">
                          <div class="model_title">用人单位（被申请人）：</div>
                          <div class="news ztxxTable2"></div>
                      </div>

                      <div class="model">
                          <div class="model_title">申请信息：</div>
                          <div class="model_content ztxxTable3"></div>
                      </div>
                          </div>
                          <div class="videi_inifo_box">
                          <video id="my_video_info" style="width:100%;height:48vh" autoplay="autoplay" controls >
                          <source src="/zzshzc/img/zjzc/stqk.mp4" >
                          不支持播放该视频
                          </video>
                          </div>
                        </div>
                    `);


        }
    });
})